package models

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type WaterDict struct {
	ID        string    `gorm:"primaryKey;type:varchar(36);not null;" json:"id"`
	Phone     string    `gorm:"column:phone;type:varchar(11);not null;default:''" json:"phone"`
	Value     string    `gorm:"column:value;type:varchar(255);not null;default:''" json:"value"`
	Stock     int       `gorm:"column:stock;type:int;not null;default:0" json:"stock"`
	Price     int       `gorm:"column:price;type:int;not null;default:0" json:"price"`
	Desc      string    `gorm:"column:desc;type:varchar(255);not null;default:''" json:"desc"`
	Balance   float64   `gorm:"column:balance;type:decimal(10,2);not null;default:0.00" json:"balance"`
	CreatedAt time.Time `gorm:"type:timestamp" json:"created_at"`
	UpdatedAt time.Time `gorm:"type:timestamp" json:"updated_at"`
}

func (w *WaterDict) TableName() string {
	return "water_dict"
}
func (w *WaterDict) BeforeCreate(tx *gorm.DB) (err error) {
	w.ID = uuid.NewString()
	w.CreatedAt = time.Now()
	w.UpdatedAt = time.Now()
	return
}

func (w *WaterDict) BeforeUpdate(tx *gorm.DB) (err error) {
	w.UpdatedAt = time.Now()
	return
}
